package com.common.oss.config;

import com.common.oss.exception.OssBaseException;
import com.common.oss.exception.OssExceptionMsg;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 创建OSS配置实类
 */
@ConfigurationProperties(value = "oss.config")
@Component
public class OssConfig {

    // Endpoint 存储对象概述
    private String endPoint ;

    /**
     * 阿里云主账号AccessKey，accessKeySecret拥有所有API的访问权限
     */
    private String accessKeyId ;
    private String accessKeySecret ;

    /**
     * 访问路径前缀  存储对象概述
     */
    private String accessPre ;

    /**
     * bucket名称
     * @return
     */
    private String bucketName;

    public String getEndPoint() {
        return endPoint;
    }

    public void setEndPoint(String endPoint) {
        if (StringUtils.isEmpty(endPoint)){
            throw new OssBaseException(OssExceptionMsg.OSS_ENDPOINT_NOT_NULL);
        }
        this.endPoint = endPoint;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        if (StringUtils.isEmpty(accessKeyId)){
            throw new OssBaseException(OssExceptionMsg.OSS_ACCESSKEYID_NOT_NULL);
        }
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        if (StringUtils.isEmpty(accessKeySecret)){
            throw new OssBaseException(OssExceptionMsg.OSS_ACCESSKEYSECRET_NOT_NULL);
        }
        this.accessKeySecret = accessKeySecret;
    }

    public String getAccessPre() {
        return accessPre;
    }

    public void setAccessPre(String accessPre) {
        if (StringUtils.isEmpty(accessPre)){
            throw new OssBaseException(OssExceptionMsg.OSS_ACCESSPRE_NOT_NULL);
        }
        this.accessPre = accessPre;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        if (StringUtils.isEmpty(bucketName)){
            throw new OssBaseException(OssExceptionMsg.OSS_BUCKETNAME_NOT_NULL);
        }
        this.bucketName = bucketName;
    }
}
